//
//  OrderApplyRefundView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/10.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "OrderApplyRefundView.h"

@interface OrderApplyRefundView()

@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) UIView *refundV;

@property (nonatomic,strong) UILabel *topTitleLB;
@property (nonatomic,strong) UILabel *leftLB;
@property (nonatomic,strong) UITextField *note_TF;
@property (nonatomic,strong) UIButton *cancelBtn;
@property (nonatomic,strong) UIButton *confirmBtn;

@property (nonatomic,strong) UIView *topLineV;
@property (nonatomic,strong) UIView *bottomLineV;
@property (nonatomic,strong) UIView *verticalLineV;


@end

@implementation OrderApplyRefundView

- (instancetype)initWithTitle:(NSString *)titleStr{
    self = [super init];
    if (self) {
        self.backgroundColor = Color_Clear;
        [self initUI];
        self.topTitleLB.text = titleStr;
    }
    return self;
}
#pragma mark - UI
-(void)initUI{
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.refundV];
    [self.refundV addSubview:self.topTitleLB];
    [self.refundV addSubview:self.leftLB];
    [self.refundV addSubview:self.note_TF];
    [self.refundV addSubview:self.topLineV];
    [self.refundV addSubview:self.bottomLineV];
    [self.refundV addSubview:self.verticalLineV];
    
    [self.refundV addSubview:self.cancelBtn];
    [self.refundV addSubview:self.confirmBtn];
    
    self.refundV.height = self.verticalLineV.bottom;
}
#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        self.bgView.backgroundColor = RGBA(0, 0, 0, 0.7f);
    }
    return _bgView;
}
- (UIView *)refundV{
    if (!_refundV) {
        _refundV = [[UIView alloc] initWithFrame:CGRectMake(15, ScreenHeight/2 - 120, ScreenWidth-30, 260)];
        _refundV.backgroundColor = UIColor.whiteColor;
        _refundV.clipsToBounds = YES;
        _refundV.layer.cornerRadius = 8;
    }
    return _refundV;
}

- (UILabel *)topTitleLB{
    if (!_topTitleLB) {
        _topTitleLB = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, ScreenWidth-70, 25)];
        _topTitleLB.textAlignment = NSTextAlignmentCenter;
        _topTitleLB.font = FontSet(18);
        _topTitleLB.textColor = MainGrayTextColor;
    }
    return _topTitleLB;
}
- (UIView *)topLineV{
    if (!_topLineV) {
        _topLineV = [[UIView alloc] initWithFrame:CGRectMake(0, self.topTitleLB.bottom+15, ScreenWidth-30, 1)];
        _topLineV.backgroundColor = MainPureColor(200);
    }
    return _topLineV;
}
- (UILabel *)leftLB{
    if (!_leftLB) {
        _leftLB = [[UILabel alloc] initWithFrame:CGRectMake(15, self.topLineV.bottom + 50, 50, 20)];
        _leftLB.textAlignment = NSTextAlignmentLeft;
        _leftLB.font = FontSet(14);
        _leftLB.textColor = MainBlackTextColor;
        _leftLB.text = @"备注:";
    }
    return _leftLB;
}
- (UITextField *)note_TF{
    if (!_note_TF) {
        _note_TF = [[UITextField alloc] initWithFrame:CGRectMake(self.leftLB.right+10, self.leftLB.top-10, ScreenWidth - 125, 40)];
        _note_TF.clipsToBounds = YES;
        _note_TF.layer.cornerRadius = 5;
        _note_TF.layer.borderWidth = 1;
        _note_TF.layer.borderColor = MainPureColor(200).CGColor;
        _note_TF.font = FontSet(14);
    }
    return _note_TF;
}
- (UIView *)bottomLineV{
    if (!_bottomLineV) {
        _bottomLineV = [[UIView alloc] initWithFrame:CGRectMake(0, self.leftLB.bottom+50, ScreenWidth-30, 1)];
        _bottomLineV.backgroundColor = MainPureColor(200);
    }
    return _bottomLineV;
}

- (UIView *)verticalLineV{
    if (!_verticalLineV) {
        _verticalLineV = [[UIView alloc] initWithFrame:CGRectMake(self.bottomLineV.width/2, self.bottomLineV.bottom, 1, 50)];
        _verticalLineV.backgroundColor = MainPureColor(200);
    }
    return _verticalLineV;
}

- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame = CGRectMake(10, self.bottomLineV.bottom+5, self.refundV.width/2-20, 40);
        [_cancelBtn setTitle:@"取消" forState:normal];
        [_cancelBtn setTitleColor:MainBlackTextColor forState:normal];
        [_cancelBtn.titleLabel setFont:FontSet(14)];
        [_cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}
- (UIButton *)confirmBtn{
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _confirmBtn.frame = CGRectMake(self.verticalLineV.right+10, self.bottomLineV.bottom+5, self.refundV.width/2-20, 40);
        [_confirmBtn setTitle:@"确定" forState:normal];
        [_confirmBtn setTitleColor:MainBlackTextColor forState:normal];
        [_confirmBtn.titleLabel setFont:FontSet(14)];
        [_confirmBtn addTarget:self action:@selector(confirmClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

#pragma mark - SEL
- (void)show {
    self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.25f animations:^{
        self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    }];
}
- (void)dismiss {
    [UIView animateWithDuration:0.25f animations:^{
        self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

//确定
-(void)confirmClick{
    if (_note_TF.text.length <= 0 || [_note_TF.text isEmpty]==YES) {
        [[XNProgressHUD shared] showWithTitle:@"请填写备注!"];
        return;
    }
    
    if (self.refundBlock) {
        self.refundBlock(self.note_TF.text);
    }
    [self dismiss];
}


#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if( [touch.view isDescendantOfView:self.refundV]) {
        return NO;
    }
    return YES;
}


@end
